import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import static junit.framework.Assert.assertTrue;

public class AddMultipleActions {

    static WebDriver driver;
    static WebDriverWait wait;
    DataChangeCheck dataChange = new DataChangeCheck();
    static int addingActionCount, actionCount;

    @BeforeClass
    public static void startFFDriverTest(){

        driver = FireFoxDriver.createFireFoxDriver();
        wait = new WebDriverWait(driver,10);
        Login loginPage = new Login(driver);
        loginPage.typeUserName();
        loginPage.typePassword();
        loginPage.clickSignIn(wait, PageVariableValues.homePageTitle);
    }
    @Test
    public void addMultipleActions (){

        WebElement AddMultipleActionsForm = driver.findElement(By.id("todo_new_action_container"));
        WebElement clickAddMultipleActions = AddMultipleActionsForm.findElement(By.id("toggle_multi"));
        clickAddMultipleActions.click();

         addingActionCount = dataChange.checkingActionCountHasIncreased(driver);

        WebElement multipleActionFrom = driver.findElement(By.id("todo-form-multi-new-action"));
        WebElement addMultipleActions = multipleActionFrom.findElement(By.id("todo_multiple_todos"));
        addMultipleActions.sendKeys("action1" + Keys.RETURN + "action2" + Keys.RETURN + "action3");

        WebElement selectProjectForActions = multipleActionFrom.findElement(By.id("multi_todo_project_name"));
        selectProjectForActions.sendKeys("TestingProject1");

        WebElement addContextToAction = multipleActionFrom.findElement(By.id("multi_todo_context_name"));
        addContextToAction.clear();
        addContextToAction.sendKeys("NA");

        WebElement submitMultipleActions = multipleActionFrom.findElement(By.id("todo_multi_new_action_submit"));
        submitMultipleActions.click();

        driver.switchTo().alert().accept();


       // actionCount = dataChange.checkingActionCountHasIncreased(driver);

       // assertTrue("the Action count should increase when multiple action has been added ", actionCount > addingActionCount);

    }

    @AfterClass
    public static void cleanUpTest(){
        driver.close();
        driver.quit();
    }

}
